//
//  SignViewManage.swift
//  nurseApp
//
//  Created by cyptt on 2022/7/8.
//

import UIKit

class SignViewManage: NSObject,UITableViewDelegate,UITableViewDataSource, UIScrollViewDelegate {

    var currentVC:TableViewSelectAllController?
    var slectAllArr:[CHSelectAllModel] = []
    var dataSources:[String] = []
    
    init(vc:TableViewSelectAllController){
        super.init()
        self.currentVC = vc
        
        self.configData()
    }
     
    func configData(){
        for _ in 0...10{
            self.dataSources.append("1")
        }
        for i in 0...10{
            let model = CHSelectAllModel()
            model.isEdit = false
            model.isSelect = false
            model.id =  i
            self.slectAllArr.append(model)
        }
    }
    

    
    /*
     正常时候
     */
    func defaulteditModel(){

        self.slectAllArr = CHSelectAllTabCell.showOrhideAllArr(isShow: false, slectAllArr: self.slectAllArr)
        self.currentVC!.selectAllView.tabView.reloadData()
    }
    
    /*
     编辑时候
     */
    func selectEditModel(){
        self.slectAllArr = CHSelectAllTabCell.showOrhideAllArr(isShow: true, slectAllArr: self.slectAllArr)
        self.currentVC!.selectAllView.tabView.reloadData()
    }
    
    
    /*
     批量签署点击了
     */
    func showAllSignClick(){
        
       
       
        self.selectEditModel()
    }
       
    /*
     取消批量签署
     */
    func cancelAllSignClick(){
   
    

        self.defaulteditModel()
    }
       
    
    /*
     点击了批量签署确定
     */
    func sureSignClick(){
        
     
     
    }
    
    /*
     选择所有
     true 选择 false 不选择
     */
    func selectAllClick(isSelect:Bool){

        self.slectAllArr = CHSelectAllTabCell.selectedOrCancelAllArr(isSelect: isSelect, slectAllArr: self.slectAllArr)
        self.currentVC!.selectAllView.tabView.reloadData()
    }
      
   
}

extension SignViewManage{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataSources.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellName:String = CHUtils.getClassName(CHSelecAlltTestTabCell.self)
        var cell:CHSelecAlltTestTabCell? = tableView.dequeueReusableCell(withIdentifier: cellName + "ID") as? CHSelecAlltTestTabCell
        if cell == nil {
            cell = Bundle.main.loadNibNamed(cellName, owner: self, options: nil)?.last as? CHSelecAlltTestTabCell
        }
//        if cell == nil {
//            cell = CHSelecAlltTestTabCell.init(style: .default, reuseIdentifier:cellName + "ID" )
//        }
//        cell?.setViewManage(viewM: self)
        
        /*
         单个按钮点击
         */
        cell?.btnClickCallBack(closure: { btn, selectAllModel in
            let arr:[Any] = CHSelectAllTabCell.changeSigle(slectAllArr: self.slectAllArr, selectModel: selectAllModel)
            let allBtnStatus:Bool = arr[0] as! Bool
            let arrSelectArr:[CHSelectAllModel] = arr[1] as! [CHSelectAllModel]
            self.slectAllArr = arrSelectArr
            self.currentVC?.selectAllBtn.isSelected = allBtnStatus
            self.currentVC!.selectAllView.tabView.reloadData()
        })
        cell?.setSelectAllModel(signEidtIem: self.slectAllArr[indexPath.row])
       
    
        return cell!
        
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 75
    }
    
 
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("点击了")

        
    }
    
 
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return false
    }
  
    
   
    func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
        print("进来了")
    }
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
     
    }
    

}


extension SignViewManage{
    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    
   
    }
  
}
